package com.zclever.kstarwar.vo;

import com.google.gson.annotations.Expose;
import org.apache.logging.log4j.util.Strings;
import org.springframework.util.CollectionUtils;

import javax.persistence.*;
import java.util.ArrayList;

/**
 * 试题实体类
 * @author zclever
 * @email 304078606@qq.com
 * @date 2019/8/20
 */
@Entity
@Table(name="t_exam")
public class Exam {
    @Id
    private int id;
    private String subject; //题干

    @Access(value=AccessType.PROPERTY) //hibernate注入对象的时候,强制执行get/set方法
    private String options;
    @Transient
    private ArrayList<String> optionList; //选项列表

    private String answer;

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getSubject() {
        return subject;
    }

    public void setSubject(String subject) {
        this.subject = subject;
    }

    public String getOptions() {
        return options;
    }

    public void setOptions(String options) {
        this.options = options;

        //选项字符串转为list列表
        if(Strings.isNotEmpty(this.options)){
            this.setOptionList(new ArrayList<String>(CollectionUtils.arrayToList(this.options.split("の"))));
        }
    }

    public ArrayList<String> getOptionList() {
        return optionList;
    }

    public void setOptionList(ArrayList<String> optionList) {
        this.optionList = optionList;
    }

    public String getAnswer() {
        return answer;
    }

    public void setAnswer(String answer) {
        this.answer = answer;
    }

    @Override
    public String toString() {
        return "Exam{" +
                "id=" + id +
                ", subject='" + subject + '\'' +
                ", options='" + options + '\'' +
                ", optionList=" + optionList +
                ", answer='" + answer + '\'' +
                '}';
    }
}
